﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SqlScheduleSetting.aspx.vb" Inherits="Map.SqlScheduleSetting" %>

<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    	<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
		<link rel="stylesheet" type="text/css" href="/_nav/menu.css">
		<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
		<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
		<link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
		<script language="javascript" src="/_common/scripts/global.js"></script>
		<script language="javascript" src="/_common/scripts/Details.js"></script>
		<script language="javascript" src="/_controls/settings.aspx"></script>
		<script language="javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/_controls/datetime/date.js"></script>
		<script language="javascript" src="/_controls/datetime/time.js"></script>
		<script language="javascript" src="/_controls/number/number.js"></script>
		<script language="javascript" src="/_controls/lookup/map_lookup.js"></script>
		<script language="javascript" src="/_controls/find/find.js"></script>
		<script language="javascript" src="/_nav/menu.js"></script>
		<script language="javascript" src="/_forms/FormBase.js"></script>
		
        <%--日志管理系统的公用JS--%>
        <script src="Js/LMSCommon.js" type="text/javascript"></script> 
</head>

<body MS_POSITIONING="GridLayout" style="padding:10px;" onload="window_onload()">
    <form id="Form1" runat="server" method="post" enableviewstate="false">
        <asp:Literal ID="Content" runat="server"></asp:Literal>
    </form>
		<table style="FONT-SIZE: 9pt;" height="100%" cellSpacing="0" cellPadding="0" width="100%">
			<tr height="1">
				<td>
					<mnu:AppFormMenu id="appFormMenu" runat="server"></mnu:AppFormMenu>
				</td>
			</tr>
			<tr>
				<td style="height:5px">
					&nbsp;
				</td>
			</tr>			
			<tr>
				<td>
					<cnt:AppForm id="appForm" runat="server" processtype="xmlhttp" onaftersave="oprAfterSave()" onbeforesave="oprBeforeSave()"></cnt:AppForm>
				</td>
			</tr>			
		</table>
</body>
</html>
<script type="text/javascript" >
    //页面初始化
    function window_onload() 
    {
        HideMenu();
        appForm._bAlert = false;
        
       //初始化界面中的数据。
        InitDefaultValue();

       if (appForm.active_start_time && appForm.active_start_time.value == " ")
       {
           appForm.active_start_time.returnValue = "";
       }
    }

    //通过后台读数据库中信息发送到前端，采用JS前端初始化界面中的数据。
    function InitDefaultValue()
    {
        if (__xml == "" )
        {
            //设默认开始日期
            var date = new Date();
            var currentDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();

            if (appForm.active_start_date)
            {
                appForm.active_start_date.setValue(currentDate);
            }

            if (appForm.overtype)
            {
                appForm.overtype.setValue(0);
                oprAfterChange(0);
            }
            return;
        }
        
        var xmlDom = XMLDOM();        
        xmlDom.loadXML(__xml);
        if (xmlDom.parseError.errorCode != 0) return "";
        
        //启用调度设置 
        var node = xmlDom.documentElement.selectSingleNode("/schedule/enabled")
        if (node != undefined && appForm.appForm_enableschedule) 
        {
            appForm.appForm_enableschedule.checked = (node.text == 1);
        }
        
        //采集时间
        node = xmlDom.documentElement.selectSingleNode("/schedule/active_start_time")
        if (node != undefined && node.text % 10000==0 && appForm.active_start_time)
        {
            var index = (node.text / 10000)
            if (index >=1 && index <= 7)
            {
                appForm.active_start_time.setValue(index);
            }
            else
            {
                appForm.active_start_time.setValue("");
            }
        }
        else
        {
            appForm.active_start_time.setValue("");
        }
        
        //结束期限类型
        node = xmlDom.documentElement.selectSingleNode("/schedule/overtype")
        if (node != undefined &&  appForm.overtype) 
        {
            appForm.overtype.setValue(node.text);
            oprAfterChange(node.text);
        }
        
        //开始日期
        node = xmlDom.documentElement.selectSingleNode("/schedule/active_start_date")
        if (node != undefined && appForm.active_start_date) 
        {
            var date = formatDate(node.text);
            appForm.active_start_date.setValue(date);
        }

        //结束日期    
        node = xmlDom.documentElement.selectSingleNode("/schedule/active_end_date")
        if (node != undefined && appForm.active_end_date) 
        {
            var date = formatDate(node.text);
            appForm.active_end_date.setValue(date);
        }
    }

    function oprAfterChange(objValue) 
    {
        var ctl = document.getElementById("active_end_date");
        if (objValue == undefined) return;
        
        try
        {
            if (objValue == 0) //有结束期限
            {
                appForm.active_end_date.setValue("");
                ctl.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "";
                ctl.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.style.display = "";
            }
            else  //无结束期限
            {
                ctl.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
                ctl.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.style.display = "none";
                appForm.active_end_date.setValue("9999-12-31");
            }        
        }
        catch(e )
        {
            return;
        }

    }

    function oprBeforeSave()
    {        
        var beginStr = appForm.active_start_date.returnValue;
        var endStr = appForm.active_end_date.returnValue;

        if (appForm.overtype.value==0 && beginStr && endStr)
        {
            var result = compareDate(beginStr, endStr);
            if (result == 1)
            {
                alert("采集结束日期不允许早于采集开始日期！");
                event.returnValue = false;
                return;
            }

        }
        appForm.userxml = "<enabled>" + appForm.appForm_enableschedule.checked + "</enabled>";
    }

    function oprAfterSave()
    {
        // 处理返回结果
       try
       {
                var xmlDom = XMLDOM();
                xmlDom.loadXML(appForm.returnxml);
                
                if (xmlDom.documentElement.attributes.getNamedItem("result").text == "true")		// 返回成功
                {
                    alert("保存设置信息成功！");
                }
                else
                {
                    alert("保存设置信息不成功：" + xmlDom.documentElement.attributes.getNamedItem("errormessage").value);
                }
        }
        catch (e)
        {
                alert("保存设置信息不成功！");
        }
        finally 
        {
            // 删除对象
            delete (oHTTP);
            delete (xmlDom);
        }
    
    }
   
    //格式化时间字符串，返回值格式如：2009-09-12
    function formatDate(dt) 
    {
        var re = "";
        var strArry = dt.split("-");

        if (strArry.length == 3)
        {
            re = strArry[0] + "-" + (strArry[1].length == 1 ? "0" + strArry[1] : strArry[1]);
            re = re + "-" + (strArry[2].length == 1 ? "0" + strArry[2] : strArry[2]);
        }
        else if(!isNaN(dt*1))
        {
            return dt.substr(0, 4) + "-" + dt.substr(4, 2) + "-" + dt.substr(6, 2); 
        }
        return re;
    }
</script>